package main

import (
	"fmt"
	"os"
)

func main() {
	fileName := "aa.txt"
	file, err := os.OpenFile(fileName, os.O_RDWR, os.ModePerm)

	defer file.Close()
	if err != nil {
		fmt.Println(err)

	}

	bb := []byte{65, 66, 66, 66}
	file.Write(bb) //直接从头开始覆盖写

	//也可以写字符串
	n, err1 := file.WriteString("哈哈哈哈哈哈我去你是真的香")
	if err1 != nil {
		fmt.Println(err1)

	} else {
		fmt.Println("写入成功写入了", n, "个字节")
	}
}
